<template>
	<view class="container">
		<view class="header">
			<view class="header-left" @tap="goBack">
				<text class="back-icon">&#xe600;</text>
			</view>
			<text class="title">我的消息</text>
			<view class="header-right"></view>
		</view>

		<!-- 消息列表 -->
		<scroll-view scroll-y class="list">
			<view v-for="(message, index) in messages" :key="message.id || index" class="message-card" @tap="viewMessageDetail(message)">
				<view class="avatar-container">
					<view class="avatar-circle">
						<text class="avatar-text">{{ message.title.charAt(0) }}</text>
						<view v-if="!message.isRead" class="unread-status">未读</view>
						<view v-else class="read-status">已读</view>
					</view>
				</view>
				<view class="content">
					<view class="header-row">
						<text class="sender">{{ message.title }}</text>
						<text class="time">{{ message.time }}</text>
					</view>
					<text class="preview">{{ message.preview }}</text>
				</view>
			</view>
			<view v-if="messages.length === 0" class="empty">暂无消息</view>
		</scroll-view>
		
		<!-- 消息详情弹窗 -->
		<view v-if="showDetailModal" class="modal-overlay" @tap="closeDetailModal">
			<view class="modal-content" @tap.stop>
				<view class="modal-header">
					<text class="modal-title">消息详情</text>
					<view class="modal-close" @tap="closeDetailModal">
						<text class="close-icon">&#xe600;</text>
					</view>
				</view>
				<view class="modal-body">
					<view class="detail-item">
						<text class="detail-label">发送者:</text>
						<text class="detail-value">{{ currentMessage.title }}</text>
					</view>
					<view class="detail-item">
						<text class="detail-label">时间:</text>
						<text class="detail-value">{{ currentMessage.fullTime }}</text>
					</view>
					<view class="detail-item">
						<text class="detail-label">内容:</text>
						<text class="detail-value content-text">{{ currentMessage.preview }}</text>
					</view>
				</view>
				<view class="modal-footer">
					<button class="confirm-btn" @tap="closeDetailModal">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<style>
	.container { 
		padding: 30rpx; 
		min-height: 100vh;
		background-color: #f5f5f5;
	}
	
	@font-face {
		font-family: 'iconfont';
		src: url('https://at.alicdn.com/t/font_2828393_4pue5j9m4q.woff2?t=1636602756377') format('woff2'),
			url('https://at.alicdn.com/t/font_2828393_4pue5j9m4q.woff?t=1636602756377') format('woff'),
			url('https://at.alicdn.com/t/font_2828393_4pue5j9m4q.ttf?t=1636602756377') format('truetype');
	}

	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
	
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 88rpx;
		background: #1976D2;
		padding: 0 20rpx;
		position: relative;
	}
	
	.header-left, .header-right {
		width: 80rpx;
		height: 88rpx;
		display: flex;
		align-items: center;
	}
	
	.back-icon {
		font-family: "iconfont" !important;
		color: #fff;
		font-size: 36rpx;
	}
	
	.title { 
		font-size: 36rpx; 
		font-weight: 700; 
		color: #fff;
	}
	
	.list { 
		max-height: calc(100vh - 200rpx); 
	}
	
	.message-card { 
		display: flex; 
		gap: 20rpx; 
		background: #fff; 
		padding: 24rpx 20rpx;
		border-bottom: 1rpx solid #eee;
		transition: all 0.3s ease;
	}
	
	.message-card:active {
		background-color: #f9f9f9;
	}
	
	.avatar-container {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-shrink: 0;
	}
	
	.avatar-circle {
		width: 96rpx;
		height: 96rpx;
		border-radius: 50%;
		background: #1976D2;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
	}
	
	.avatar-text {
		color: #ffffff;
		font-size: 28rpx;
		font-weight: 600;
	}
	
	.unread-status {
		position: absolute;
		top: -8rpx;
		right: -8rpx;
		min-width: 32rpx;
		height: 32rpx;
		background: #ff3b30;
		border-radius: 16rpx;
		color: white;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0 6rpx;
		font-weight: 600;
	}
	
	.read-status {
		position: absolute;
		top: -8rpx;
		right: -8rpx;
		min-width: 32rpx;
		height: 32rpx;
		background: #4caf50;
		border-radius: 16rpx;
		color: white;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0 6rpx;
		font-weight: 600;
	}
	
	.content {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		min-width: 0;
	}
	
	.header-row {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10rpx;
	}
	
	.sender {
		font-size: 32rpx;
		color: #333;
		font-weight: 600;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	
	.time {
		font-size: 24rpx;
		color: #999;
		flex-shrink: 0;
		margin-left: 20rpx;
	}
	
	.preview {
		font-size: 26rpx;
		color: #666;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}
	
	.empty {
		text-align: center;
		padding: 40rpx;
		color: #999;
		font-size: 28rpx;
	}
	
	/* 弹窗样式 */
	.modal-overlay {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 9999;
	}
	
	.modal-content {
		background: #fff;
		border-radius: 20rpx;
		width: 80%;
		max-width: 600rpx;
		max-height: 80vh;
		overflow: hidden;
		animation: modalFadeIn 0.3s ease;
	}
	
	@keyframes modalFadeIn {
		from {
			opacity: 0;
			transform: scale(0.8);
		}
		to {
			opacity: 1;
			transform: scale(1);
		}
	}
	
	.modal-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #eee;
	}
	
	.modal-title {
		font-size: 36rpx;
		font-weight: 600;
		color: #333;
	}
	
	.modal-close {
		width: 40rpx;
		height: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.close-icon {
		font-family: "iconfont" !important;
		color: #999;
		font-size: 30rpx;
		transform: rotate(180deg);
	}
	
	.modal-body {
		padding: 30rpx;
		max-height: 60vh;
		overflow-y: auto;
	}
	
	.detail-item {
		margin-bottom: 30rpx;
	}
	
	.detail-item:last-child {
		margin-bottom: 0;
	}
	
	.detail-label {
		font-size: 28rpx;
		color: #999;
		margin-bottom: 10rpx;
		display: block;
	}
	
	.detail-value {
		font-size: 30rpx;
		color: #333;
	}
	
	.content-text {
		line-height: 1.6;
		white-space: pre-wrap;
		word-wrap: break-word;
	}
	
	.modal-footer {
		padding: 30rpx;
		text-align: center;
		border-top: 1rpx solid #eee;
	}
	
	.confirm-btn {
		width: 100%;
		height: 80rpx;
		background: #1976D2;
		color: #fff;
		border: none;
		border-radius: 10rpx;
		font-size: 32rpx;
		font-weight: 600;
	}
</style>